import bridge from '@king-fisher/bridge';

interface HQParamsType {
  protocolId: number;
  pageId: number;
  requestDic: string;
  onlineId: string;
}

export function getNativeHqData(HQParams: HQParamsType) {
  return new Promise(resolve => {
    bridge.callNativeHandlerObj(
      'UnifiedRequest',
      'abort',
      [HQParams as any],
      () => {
        bridge.callNativeHandlerObj(
          'UnifiedRequest',
          'request',
          [HQParams as any],
          (res: any) => {
            if (typeof res === 'string') {
              const data = JSON.parse(res);
              resolve(data);
            } else {
              resolve(res);
            }
          },
          'objectID'
        );
      },
      'objectID'
    );
  });
}
